package MP;

import MP.ASTs.AST;
import MP.codegeneration.CodeGenerator;
import MP.lexicalanalysis.ErrorReporter;
import MP.lexicalanalysis.Scanner;
import MP.syntaxanalysis.Parser;
public class MPC {
	public final static String CLASSNAME = "MPout";
	public final static String LIBNAME = "MP/lib/Lib";
	public final static String INNERPREFIX = "_";
	/** the entry point
	 **/
	public static void main(String[] args) {
		ErrorReporter reporter = new ErrorReporter();
		try {
			int paNum = args.length;
			if (paNum != 1)
				throw new UsageException();
			String fileName = args[0];
			Scanner s = new Scanner(fileName, reporter);
			Parser p = new Parser(s,reporter);
			AST ast = p.parse();
			//StaticChecker checker = new StaticChecker(ast);
			//checker.parse();
			CodeGenerator g = new CodeGenerator(ast);
			g.parse();
		} catch (UsageException e) {
			reporter.reportError(e.getMessage());
		} catch (CompilationException ce){
			reporter.reportError(ce.getMessage());			
		}
		
	}
    public static int hash(String s) {
	    return s.hashCode();
    }
	static String usage() {
		return "Usage: java MP.MPC <input file>";
	}
}

class UsageException extends CompilationException {
	public String getMessage() {
		return MPC.usage();
	}
}
